Conversation
The tipstream.clar contract defines (define-constant min-fee u1) which enforces a minimum platform fee of 1 uSTX whenever fee basis points are greater than zero. The frontend needs this constant to mirror that rule in its fee calculations.
When fee basis points are greater than zero, the contract guarantees a minimum fee of 1 uSTX even if the raw calculation rounds to zero. This brings feeForTip in line with the contract calculate-fee function so the fee preview in SendTip accurately reflects on-chain behavior.
The contract deducts max(raw-fee, 1) from the tip amount when fee basis points are positive. recipientReceives now mirrors this so the Recipient receives line in the fee preview matches what actually lands on-chain.
The post-condition ceiling must account for the minimum fee guarantee. Without this, sub-threshold tips could set a ceiling that is too low, causing the transaction to be rejected by the post-condition check.
Needed for the upcoming minimum fee enforcement tests.
Verifies feeForTip(1) returns MIN_FEE_USTX when the raw calculation would round to less than the contract minimum.
100 * 50 / 10000 = 0.5 which ceils to 1, matching the minimum.
199 is the last amount before the raw ceil crosses above 1.
At exactly 200 uSTX, raw fee is 1.0 which ceils to 1. This is the exact threshold where the calculated fee equals the minimum.
First amount where the raw ceil exceeds MIN_FEE_USTX.
Sweeps across multiple sub-threshold amounts to confirm the minimum fee guarantee holds for all of them.
The minimum fee only applies when fee basis points are positive. When the fee is disabled (bps=0) the result should always be 0.
A 10 uSTX tip should deduct 11 uSTX total (10 + 1 min fee).
A 10 uSTX tip should yield 9 uSTX to the recipient after the 1 uSTX minimum fee is applied.
The entire tip is consumed by the minimum fee at this extreme.
No minimum fee applies when bps is zero.
Verifies the post-condition ceiling accounts for the minimum fee even at the smallest possible tip amount.
Verify that totalDeduction = amount + feeForTip holds at the minimum fee boundary.
No minimum fee should apply and all calculations should be consistent with zero fee deduction.
Restoring test that was lost during linter reformatting.
Restoring the five cross-function tests that validate fee calculation agreement across feeForTip, totalDeduction, recipientReceives, and maxTransferForTip at the minimum fee boundary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #242